package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-31 17:34
 **/
public class LeetCode121 {

    public int maxProfit(int[] prices) {
        //最大利润
        int max = 0;
        //股票最低价格
        int min = prices[0];
        for (int i = 1; i < prices.length; ++i) {
            min = Math.min(min, prices[i]);
            max = Math.max(max, prices[i] - min);
        }

        return max;
    }

}
